package com.qiang.test02;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class Recvice {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(15000);


        //接收数据
        Socket accept = ss.accept();


        //创建输入流
        //从服务器获取输入流读取文件
        InputStream inputStream = accept.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(inputStream);


        //存储到本地
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\cc\\" + UUID.randomUUID().toString() + ".jpg"));
        byte[] bb = new byte[1024];
        int len;
        while ((len = bis.read(bb)) != -1) {
            bos.write(bb, 0, len);
        }

        //给服务器返回信息
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
//        bw.write("上传成功");
//        bw.flush();

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();

        bis.close();
        bos.close();
        accept.close();
    }
}
